package com.qinggeng.project.system.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.UserAddress;
import com.qinggeng.project.system.service.IUserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 用户收货地址信息Controller
 *
 * @author qinggeng
 * @date 2020-05-28
 */
@RestController
@RequestMapping("/system/address")
public class UserAddressController extends BaseController
{
    @Autowired
    private IUserAddressService userAddressService;

    /**
     * 查询用户收货地址信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserAddress userAddress)
    {
        startPage();
        List<UserAddress> list = userAddressService.selectUserAddressList(userAddress);
        return getDataTable(list);
    }

    /**
     * 导出用户收货地址信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:address:export')")
    @Log(title = "用户收货地址信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserAddress userAddress)
    {
        List<UserAddress> list = userAddressService.selectUserAddressList(userAddress);
        ExcelUtil<UserAddress> util = new ExcelUtil<UserAddress>(UserAddress.class);
        return util.exportExcel(list, "address");
    }

    /**
     * 获取用户收货地址信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:address:query')")
    @GetMapping(value = "/{addressId}")
    public AjaxResult getInfo(@PathVariable("addressId") Long addressId)
    {
        return AjaxResult.success(userAddressService.selectUserAddressById(addressId));
    }

    /**
     * 新增用户收货地址信息
     */
    @PreAuthorize("@ss.hasPermi('system:address:add')")
    @Log(title = "用户收货地址信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserAddress userAddress)
    {
        return toAjax(userAddressService.insertUserAddress(userAddress));
    }

    /**
     * 修改用户收货地址信息
     */
    @PreAuthorize("@ss.hasPermi('system:address:edit')")
    @Log(title = "用户收货地址信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserAddress userAddress)
    {
        return toAjax(userAddressService.updateUserAddress(userAddress));
    }

    /**
     * 删除用户收货地址信息
     */
    @PreAuthorize("@ss.hasPermi('system:address:remove')")
    @Log(title = "用户收货地址信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{addressIds}")
    public AjaxResult remove(@PathVariable Long[] addressIds)
    {
        return toAjax(userAddressService.deleteUserAddressByIds(addressIds));
    }
}
